<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Mosaddek">
    <meta name="keyword" content="FlatLab, Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, Retina">
    <link rel="shortcut icon" href="<?php echo base_url() ?>Resources/Admin/img/favicon.png">

    <title>List item</title>
      <?php // echo current_url(); exit; ?>
    <!-- Bootstrap core CSS -->
    <link href="<?php echo base_url() ?>Resources/Admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url() ?>Resources/Admin/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="<?php echo base_url() ?>Resources/Admin/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="<?php echo base_url() ?>Resources/Admin/css/style.css" rel="stylesheet">
    <link href="<?php echo base_url() ?>Resources/Admin/css/style-responsive.css" rel="stylesheet" />
    <link rel="stylesheet" href="<?php echo base_url() ?>Resources/Admin/js/autocomplete/jquery-ui.css">
<script src="<?php echo base_url() ?>Resources/Admin/js/jquery.js"></script>
  <script src="<?php echo base_url() ?>Resources/Admin/js/autocomplete/jquery-ui.js"></script>
    
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="js/html5shiv.js"></script>
      <script src="js/respond.min.js"></script>
    <![endif]-->  
        
        <!-- ajax search -->
        <script type="text/javascript">
       
        </script>
        <!-- ajax search -->
        
    <!-- phân trang jquery -->
       <script type="text/javascript">
        $(document).ready(function(){
        		phantrang();
        });
        function phantrang()
        {
            $("#jquery_link a").click(function(){
        		var url = $(this).attr("href");
               //  alert(url);
        		$.ajax({
        			type: "POST",
        			url: url,
        			data: "ajax",
        			async: true,
        			beforeSend: function(){
        				$("#content1").html("");
                      //  alert('abc');
        			},
        			success: function(kq){
        				$("#content1").html(kq);
        			}
        		})
        	//	return false;
        	});	
        }
        </script>
    <!-- phân trang jquery -->
    
    <style>
  .custom-combobox {
    position: relative;
    display: inline-block;
  }
  .custom-combobox-toggle {
    position: absolute;
    top: 0;
    bottom: 0;
    margin-left: -1px;
    padding: 0;
  }
  .custom-combobox-input {
    margin: 0;
    padding: 5px 10px;
  }
  .ui-autocomplete {
            max-height: 300px;
            overflow-y: auto;
            /* prevent horizontal scrollbar */
            overflow-x: hidden;
            /* add padding to account for vertical scrollbar */
            padding-right: 20px;
    }
    /* IE 6 doesn't support max-height
     * we use height instead, but this forces the menu to always be this tall
     */
    * html .ui-autocomplete {
        height: 300px;
    }
  </style>
  
  <script>
  (function( $ ) {
    $.widget( "custom.combobox", {
      _create: function() {
        this.wrapper = $( "<span>" )
          .addClass( "custom-combobox" )
          .insertAfter( this.element );
 
        this.element.hide();
        this._createAutocomplete();
        this._createShowAllButton();
      },
 
      _createAutocomplete: function() {
        var selected = this.element.children( ":selected" ),
          value = selected.val() ? selected.text() : "";
 
        this.input = $( "<input>" )
          .appendTo( this.wrapper )
          .val( value )
          .attr( "id", "combo" )
          .attr("name","text_search")
          .addClass( "form-control searchbox" )
          .autocomplete({
            delay: 0,
            minLength: 0,
            source: $.proxy( this, "_source" )
          })
          .tooltip({
            tooltipClass: "ui-state-highlight"
          });
 
        this._on( this.input, {
          autocompleteselect: function( event, ui ) {
            ui.item.option.selected = true;
            this._trigger( "select", event, {
              item: ui.item.option
            });
          },
 
          autocompletechange: "_removeIfInvalid"
        });
      },
 
      _createShowAllButton: function() {
        var input = this.input,
          wasOpen = false;
 
        $( "<a>" )
          .attr( "tabIndex", -1 )
          .attr( "title", "Hiện tất cả hero" )
          .tooltip()
          .appendTo( this.wrapper )
          .button({
            icons: {
              primary: ""
            },
            text: false
          })
          .removeClass( "ui-corner-all" )
          .addClass( "ui-button ui-widget ui-state-default ui-button-icon-only custom-combobox-toggle ui-corner-right" )
          .mousedown(function() {
            wasOpen = input.autocomplete( "widget" ).is( ":visible" );
          })
          .click(function() {
            input.focus();

            // Close if already visible
            if ( wasOpen ) {
              return;
            }
 
            // Pass empty string as value to search for, displaying all results
            input.autocomplete( "search", "" );
          });
      },
 
      _source: function( request, response ) {
        var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
        response( this.element.children( "option" ).map(function() {
          var text = $( this ).text();
          if ( this.value && ( !request.term || matcher.test(text) ) )
            return {
              label: text,
              value: text,
              option: this
            };
        }) );
      },
 
      _removeIfInvalid: function( event, ui ) {
 
        // Selected an item, nothing to do
        if ( ui.item ) {
          return;
        }
 
        // Search for a match (case-insensitive)
        var value = this.input.val(),
          valueLowerCase = value.toLowerCase(),
          valid = false;
        this.element.children( "option" ).each(function() {
          if ( $( this ).text().toLowerCase() === valueLowerCase ) {
            this.selected = valid = true;
            return false;
          }
        });
 
        // Found a match, nothing to do
        if ( valid ) {
          return;
        }
 
        // Remove invalid value
        this.input
          .val( "" )
          .attr( "title", value + "không có hero này" )
          .tooltip( "open" );
        this.element.val( "" );
        this._delay(function() {
          this.input.tooltip( "close" ).attr( "title", "" );
        }, 2500 );
        this.input.autocomplete( "instance" ).term = "";
      },
 
      _destroy: function() {
        this.wrapper.remove();
        this.element.show();
      }
    });
  })( jQuery );
 
  $(function() {
    $( "#combobox" ).combobox();
    $( "#toggle" ).click(function() {
      $( "#combobox" ).toggle();
    });
  });
  </script>
    
 
        
        
        <style>
        #jquery_link{
        	margin-top:5px;	
        }
        </style>
  </head>

  <body>

  <section id="container" class="">
      <!--header start-->
      <header class="header white-bg">
           <?php $this->load->view('admin_layout/header') ?>
        </header>
      <!--header end-->
      <!--sidebar start-->
       <aside>
          <div id="sidebar"  class="nav-collapse ">
              <?php $this->load->view('admin_layout/sidebar') ?>
          </div>
      </aside>
      <!--sidebar end-->
      <!--main content start-->
      <section id="main-content">
          <section class="wrapper">
              <!-- page start-->
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                              Tìm kiếm
                          </header>
                          <div class="panel-body">
                              <form class="form-inline" action="<?php echo base_url('item/show_item_search') ?>" method="POST" role="form">
                               
                                  
                             <div class="row">
                             <div class="col-lg-12">
                               
                                  <div>
                                                          <center><label>Tìm theo tên Item/Set Item</label></center>
                                                          <input type="text" class="form-control" id="item_name" name="item_name" placeholder="Nhập tên Item/Set Item" style="text-align: center;" width="100%" />
                                                      </div>
                                                      </div>
                                                      <br />
                              <div class="col-lg-3">
                                  <div class="form-group">
                                      <div class="ui-widget" ><label>Theo tên Hero</label> 
                                          <select id="combobox" name="cboHero">
                                            <?php if(isset($hero)) { 
                                                foreach($hero as $he) {
                                                ?>
                                            <option value="<?php echo $he->HERO_NAME ?>" <?php if(@$_POST['text_search'] == $he->HERO_NAME) echo "selected=selected"; 
                                                                                                else if(isset($hero_search)) 
                                                                                                    if($hero_search == $he->HERO_NAME) echo "selected=selected";
                                            
                                            ?>>  <?php echo $he->HERO_NAME ?></option>
                                            <?php } } ?>
                                          </select>
                                        </div>
                                  </div>
                              </div>
                              
                              <div class="col-lg-3">
                              <label> Theo rarity</label> 
                                   <div class="btn-group">
                                  <select class="form-control" name="cboRarity">
                                  <option value="All">All</option>
                                         <?php if(isset($rarity)) { 
                                            foreach($rarity as $ra) {
                                                if($ra->ITEM_RARITY != '') {
                                            ?>
                                        <option value="<?php echo $ra->ITEM_RARITY ?>" <?php if(@$_POST['cboRarity'] == $ra->ITEM_RARITY) echo "selected=selected"; 
                                                                                                else if(isset($rarity_search))
                                                                                                    if($rarity_search == $ra->ITEM_RARITY) echo "selected=selected";
                                        
                                        ?>><?php echo $ra->ITEM_RARITY ?></option>
                                        
                                        <?php } } } ?>
                                        
                                    </select>
                                 </div>
                               </div>
                               
                               <div class="col-lg-3">
                              <label> Theo Item_type</label> 
                                   <div class="btn-group">
                                  <select class="form-control" name="cboType">
                                  <option value="All">All</option>
                                         <?php if(isset($type)) { 
                                            foreach($type as $ty) {
                                                if($ty->ITEM_TYPE != '' && $ty->ITEM_TYPE != "Other") {
                                            ?>
                                        <option value="<?php echo $ty->ITEM_TYPE ?>" <?php if(@$_POST['cboType'] == $ty->ITEM_TYPE) echo "selected=selected"; 
                                                                                                else if(isset($type_search))
                                                                                                    if($type_search == $ty->ITEM_TYPE) echo "selected=selected";
                                        
                                        ?>><?php echo $ty->ITEM_TYPE ?></option>
                                        
                                        <?php } } } ?>
                                        <option value="Other">Other</option>
                                    </select>
                                 </div>
                               </div>
                               
                               </div> 
                               <br />  
                                  <button type="submit" class="btn btn-info">Tìm kiếm</button>
                              </form>

                          </div>
                      </section>

                  </div>
                            
              <div class="row">
              <div class="col-sm-12">
                      <section class="panel">
                          <header class="panel-heading">
                          <div class="col-sm-4">
                               <a href="#myModal_them" data-toggle="modal" class="btn btn-round btn-info">
                                    Thêm Item mới
                                         </a>  
                                         <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal_them" class="modal fade">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                              <h4 class="modal-title">Thêm Item</h4>
                                          </div>
                                          <div class="modal-body">
                                            <form action="<?php
                                                          //name hero, rarity, type, image , price
                                                          echo base_url('item/add_new_item');
                                                          ?>" method="POST" role="form">
                                                          
                                                  <div class="form-group">
                                                      <label for="name">Tên item</label>
                                                      <input type="text" class="form-control" id="name" name="name" placeholder="Tên Item" />
                                                  </div>
                                                  <div class="form-group">
                                                  <label for="hero_insert">Tên hero</label>
                                                      <select id="hero_insert" class="form-control" name="hero_insert">
                                                            <?php if(isset($hero)) { 
                                                                foreach($hero as $he) {
                                                                ?>
                                                            <option value="<?php echo $he->HERO_NAME ?>">  <?php echo $he->HERO_NAME ?></option>
                                                            <?php } } ?>
                                                          </select>
                                                  </div>
                                                  <div class="form-group">
                                                   <label for="rarity_insert">Rarity</label>
                                                                      <select class="form-control" name="rarity_insert">
                                                                      <option value=""></option>
                                                         <?php if(isset($rarity)) { 
                                                            foreach($rarity as $ra) {
                                                                if($ra->ITEM_RARITY != '') {
                                                            ?>
                                                        <option value="<?php echo $ra->ITEM_RARITY ?>" ><?php echo $ra->ITEM_RARITY ?></option>
                                                        
                                                        <?php } } } ?>
                                                        
                                                    </select>
                                                  </div>
                                                  <div class="form-group">
                                                   <label for="type_insert">Type</label>
                                                      <select class="form-control" name="type_insert">
                                                                 <?php if(isset($type)) { 
                                                                    foreach($type as $ty) {
                                                                        if($ty->ITEM_TYPE != '' && $ty->ITEM_TYPE != "Other") {
                                                                    ?>
                                                                <option value="<?php echo $ty->ITEM_TYPE ?>"><?php echo $ty->ITEM_TYPE ?></option>
                                                                
                                                                <?php } } } ?>
                                                                <option value="Other">Other</option>
                                                            </select>
                                                  </div>
                                                  
                                                  <div class="form-group">
                                                      <label for="price">Giá bán:</label>
                                                      <input type="text" class="form-control" id="price" name="price" placeholder="Money" />
                                                  </div>
                                                  <div class="form-group">
                                                      <label for="image">Image URL:</label>
                                                      <input type="text" class="form-control" id="image" name="image" placeholder="Link" />
                                                  </div>
                                                   <input type="hidden" name="url1" value="<?php echo current_url() ?>" />
                                                  <button type="submit" onClick="alert('Thêm Item thành công')" class="btn btn-info">Xác nhận</button>
                                              </form>

                                          </div>

                                      </div>
                                  </div>
                              </div>
                             </div>
                             <div class="col-sm-4">
                                 <a href="#myModalsaleoffchung" data-toggle="modal" class="btn btn-round btn-info">
                                        Giá trị SaleOff chung hiện tại : <?php $salechung = $this->m_item->get_new_saleoff_chung();
                                                                                echo $salechung[0]->SAMPLE_VALUE;
                                         ?>
                                             </a>  
                                             <div aria-hidden="true" aria-labelledby="myModalLabel1" role="dialog" tabindex="-1" id="myModalsaleoffchung" class="modal fade">
                                      <div class="modal-dialog">
                                          <div class="modal-content">
                                              <div class="modal-header">
                                                  <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                                  <h4 class="modal-title">Cập nhật sale off chung cho tất cả item</h4>
                                              </div>
                                              <div class="modal-body">
    
                                                              <form class="form-horizontal" method="POST" action="<?php echo base_url('item/cap_nhat_sale_off_chung') ?>" role="form">
                                                                  <div class="form-group">
                                                                      <label for="saleoffchung" id="" class="col-lg-2 col-sm-2 control-label">Sale Off chung:</label>
                                                                      <div class="col-lg-10">
                                                                          <input type="hidden" name="current" value="<?php echo current_url() ?>" />
                                                                           <input type="date" class="form-control" name="from" />
                                                                              <span class="input-group-addon">Đến</span>
                                                                              <input type="date" class="form-control" name="to" />
                                                                            <span class="help-block">Nhập khoảng thời gian saleOff</span>
                                                                          <input type="text" class="form-control" id="saleoffchung" name="saleoffchung" placeholder="Nhập giá trị sale off mới" />
                                                                      </div>
                                                                  </div>
                                                                  <div class="form-group">
                                                                      <div class="col-lg-offset-2 col-lg-10">
                                                                          <button type="submit" onClick="alert('Cập nhật thành công')" class="btn btn-info">Cập nhật</button>
                                                                      </div>
                                                                  </div>
                                                              </form>
    
                                              </div>
    
                                          </div>
                                      </div>
                                  </div>
                             </div>     
                          </header>
                                                                                     
                          <table class="table table-striped table-hover table-bordered">
                              <thead>
                              <tr>
                                  <th>STT</th>
                                  <th>SET ITEMS NAME</th>
                                    <th>ITEM NAME</th>
                                    <th>HERO NAME</th>
                                    <th>ITEM RARITY</th>
                                    <th>ADD DATE</th>
                                    <th>PRICE_ON_MARKET</th>
                                    <th>PRICE</th>
                                    <th>SALE OFF RIÊNG</th>
                              </tr>
                              </thead>
                              <div id="content">
                              <tbody>
                              <?php
                          			$stt = 0;
                                   // $index = 0;
                                  //  var_dump($info); exit;
                                  if(is_array($info)) {
                        			foreach($info as $i){
                        				$stt++; ?>
                                        <tr>                                        
                                      <td><?php echo $stt; ?></td>     
                                       <td><?php echo $i->SET_ITEMS_NAME; ?></td>                                 
                                    <td><?php echo $i->ITEM_NAME; ?>
                                     <a href="<?php echo base_url('item/update_item/'.$i->ITEM_ID) ?>"><button style="float: right;" class="btn btn-success btn-xs"><i class="icon-pencil"></i></button></a>
                                    
                                    </td>
                                    <td><?php echo $i->HERO_NAME; ?></td>
                                    <td><?php echo $i->ITEM_RARITY; ?></td>
                                    <td><?php echo $i->ADD_DATE; ?></td>
                                    <td><?php echo $i->PRICE_MARKET; ?></td>
                                    <td>
                                    <a href="#myModal_<?php echo $i->ITEM_ID ?>" data-toggle="modal" class="btn btn-xs btn-info">
                                    
                                          <?php if($i->PRICE != '') echo $i->PRICE; else echo 'chưa cập nhật giá' ?>
                                         </a>  
                                         <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal_<?php echo $i->ITEM_ID ?>" class="modal fade">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                              <h4 class="modal-title">Cập nhật giá Item</h4>
                                          </div>
                                          <div class="modal-body">

                                                          <form class="form-horizontal" method="POST" action="<?php echo base_url('item/cap_nhat_gia') ?>" role="form">
                                                          <div class="form-group">
                                                                  <label for="gia_market" class="col-lg-2 col-sm-2 control-label">Giá market</label>
                                                                  <div class="col-lg-10">
                                                                      <input type="text" class="form-control" id="gia_market" value="<?php echo $i->PRICE_MARKET ?>" readonly />
                                                                  </div>
                                                              </div>
                                                              <div class="form-group">
                                                                  <label for="gia_cu" class="col-lg-2 col-sm-2 control-label">Giá cũ</label>
                                                                  <div class="col-lg-10">
                                                                      <input type="text" class="form-control" id="gia_cu" value="<?php echo $i->PRICE ?>" readonly />
                                                                  </div>
                                                              </div>
                                                              <div class="form-group">
                                                                  <label for="gia_moi" id="" class="col-lg-2 col-sm-2 control-label">Giá mới</label>
                                                                  <div class="col-lg-10">
                                                                      <input type="hidden" name="item_id" value="<?php echo $i->ITEM_ID ?>" />
                                                                      <input type="hidden" name="current" value="<?php echo current_url() ?>" />
                                                                      <input type="text" class="form-control" id="gia_moi" name="gia_moi" placeholder="Nhập giá mới" />
                                                                  </div>
                                                              </div>
                                                              <div class="form-group">
                                                                  <div class="col-lg-offset-2 col-lg-10">
                                                                      <button type="submit" onClick="alert('Cập nhật thành công')" class="btn btn-info">Cập nhật</button>
                                                                  </div>
                                                              </div>
                                                          </form>

                                          </div>

                                      </div>
                                  </div>
                              </div>
                                      
                                    </td>
                                    <td>
                                    <a href="#myModalsale_<?php echo $i->ITEM_ID ?>" data-toggle="modal" class="btn btn-xs btn-info">
                                    
                                          <?php if($i->IS_SALE != 0 && $i->IS_SALE != null ) {
                                             $sale = $this->m_item->get_new_saleoff_by_itemid($i->ITEM_ID); echo $sale[0]->SOVALUE;
                                          } else echo 'None'  ?>
                                         </a>  
                                         <div aria-hidden="true" aria-labelledby="myModalLabel1" role="dialog" tabindex="-1" id="myModalsale_<?php echo $i->ITEM_ID ?>" class="modal fade">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                              <h4 class="modal-title">Cập nhật saleoff riêng cho item</h4>
                                          </div>
                                          <div class="modal-body">
                                                          <form class="form-horizontal" method="POST" action="<?php echo base_url('item/cap_nhat_sale_off_rieng') ?>" role="form">
                                                              <div class="form-group">
                                                                  <label for="saleoffrieng" id="" class="col-lg-2 col-sm-2 control-label">Sale Off Riêng:</label>
                                                                  <div class="col-lg-10">
                                                                      <input type="hidden" name="item_id" value="<?php echo $i->ITEM_ID ?>" />
                                                                      <input type="hidden" name="current" value="<?php echo current_url() ?>" />
                                                                      
                                                                      <input type="date" class="form-control" name="from" />
                                                                      <span class="input-group-addon">Đến</span>
                                                                      <input type="date" class="form-control" name="to" />

                                                                  <span class="help-block">Nhập khoảng thời gian saleOff</span>
                                                                      <input type="text" class="form-control" id="saleoffrieng" name="saleoffrieng" placeholder="Nhập giá trị sale off mới" />
                                                                  </div>
                                                              </div>
                                                              <div class="form-group">
                                                                  <div class="col-lg-offset-2 col-lg-10">
                                                                      <button type="submit" onClick="alert('Cập nhật thành công')" class="btn btn-info">Cập nhật</button>
                                                                  </div>
                                                              </div>
                                                          </form>

                                          </div>

                                      </div>
                                  </div>
                              </div>
                                    </td>
                                    </tr>	<?php //	$index++;	
                        			} }
	                           	?>
                              </tbody>
                          </table>
                          <div id="jquery_link" align="center">
                        		<?php echo $pagination;?>
                        	</div>
                            </div>
                      </section>
                  </div>
              </div>
              <!-- page end-->
          </section>
      </section>
      <!--main content end-->
      <!--footer start-->
       <footer class="site-footer">
           <?php $this->load->view('admin_layout/footer') ?>
      </footer>
      <!--footer end-->
  </section>

    <!-- js placed at the end of the document so the pages load faster -->
    
    <script src="<?php echo base_url() ?>Resources/Admin/js/bootstrap.min.js"></script>
    <script class="include" type="text/javascript" src="<?php echo base_url() ?>Resources/Admin/js/jquery.dcjqaccordion.2.7.js"></script>
    <script src="<?php echo base_url() ?>Resources/Admin/js/jquery.scrollTo.min.js"></script>
    <script src="<?php echo base_url() ?>Resources/Admin/js/jquery.nicescroll.js" type="text/javascript"></script>
    <script src="<?php echo base_url() ?>Resources/Admin/js/respond.min.js" ></script>

    <!--common script for all pages-->
    <script src="<?php echo base_url() ?>Resources/Admin/js/common-scripts.js"></script>
                                            <script type="text/javascript">
                                                		$("#price,#gia_moi").keydown(function (e) {
                                                		//  alert('abc');
                                                		    // Allow: backspace, delete, tab, escape, enter and .
                                                		    if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
                                                		         // Allow: Ctrl+A
                                                		        (e.keyCode == 65 && e.ctrlKey === true) || 
                                                		         // Allow: home, end, left, right
                                                		        (e.keyCode >= 35 && e.keyCode <= 39)) {
                                                		             // let it happen, don't do anything
                                                		             return;
                                                		    }
                                                		    // Ensure that it is a number and stop the keypress
                                                		    if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
                                                		        e.preventDefault();
                                                		    }
                                                		});
                                                	</script>

  </body>
</html>